<?php


namespace App\Http\Controllers\Mini\Shop;

use App\Services\FeedbackService;
use App\Services\UploadService;
use App\Services\UserService;
use App\Traits\ResourceTrait;
use Illuminate\Contracts\Validation\Validator;
use App\Http\Requests\Mini\Shop\Feedback;

/**
 * 反馈控制器
 * Class FeedbackController
 * @package App\Http\Controllers\Mini\Shop
 */
class FeedbackController
{
    use ResourceTrait;

    public $feedbackService;
    public $userService;

    /**
     * FeedbackController constructor.
     */
    public function __construct()
    {
        $this->feedbackService = new FeedbackService();
        $this->userService = new UserService();
    }

    /**
     * 2021/3/10--10:33
     * @param \App\Http\Requests\Mini\Shop\Feedback $request
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:addFeedback
     * @effect:添加反馈
     */
    public function addFeedback(Feedback $request)
    {
        $validated = $request->validated();
        if (is_array($validated['feedback_images'])) {
            $validated['feedback_images'] = implode('', $validated['feedback_images']);
        }
        $validated['user_id'] = $this->userService->getUserInfo()['id'];
        return $this->feedbackService->addFeedback($validated);
    }


    /**
     * 2021/3/10--13:19
     * @param UploadService $upload_service 上传字段 file
     * @return mixed
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:feedback_upload
     * @effect:反馈图片上传接口
     */
    public function feedback_upload(UploadService $upload_service)
    {
        $user_info = $this->userService->getUserInfo();
        $rs = $upload_service->feedback($user_info['id']);
        if ($rs['status']) {
            return $this->format($rs['data'], $rs['msg']);
        } else {
            return $this->format_error($rs['msg']);
        }
    }

    public function __destruct()
    {
        $this->feedbackService;
        // TODO: Implement __destruct() method.
    }
}
